package so.sao.code.service.domain.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import so.sao.code.service.domain.entity.EnterpriseOperationLog;
import so.sao.code.service.domain.event.ChangeChildCodeUpEvent;
import so.sao.code.service.repository.EnterpriseOperationLogDao;
import so.sao.data.dto.response.EnterpriseDTO;
import so.sao.data.feign.client.EnterpriseClient;

/**
 * Created by Administrator on 2017/10/27.
 */
@Component
public class ChangeChildCodeUpEventHandler {
    @Autowired
    EnterpriseOperationLogDao enterpriseOperationLogDao;
    @Autowired
    EnterpriseClient enterprisesClient;

    @Async
    @EventListener
    public void logAction(ChangeChildCodeUpEvent event) {
        EnterpriseDTO enterpriseDto = enterprisesClient.findById(event.getEseId());
        enterpriseOperationLogDao.save(new EnterpriseOperationLog(event.getEseId(), enterpriseDto.getName(), event.getAction(), event.getCount(), event.getIp()));
    }
}
